<template>
  <div class="exam-list-container">
    <el-table
        :data="examsList"
        border
        style="width: 100%;"
    >
      <el-table-column
          prop="examId"
          label="考试ID"
          width="120"
      />
      <el-table-column
          prop="schoolId"
          label="学校ID"
          width="120"
      />
      <el-table-column
          prop="examName"
          label="考试名称"
      />
      <el-table-column
          prop="examType"
          label="考试类型"
          width="120"
      />
      <el-table-column
          prop="startTime"
          label="开始时间"
          width="220"
      />
      <el-table-column
          prop="endTime"
          label="结束时间"
          width="220"
      />
      <el-table-column
          prop="durationMinutes"
          label="时长(分钟)"
          width="120"
      />
      <el-table-column
          prop="status"
          label="状态"
          width="120"
      />
      <el-table-column
          label="操作"
          width="120"
      >
        <template #default="scope">
          <el-button
              type="primary"
              @click="handleStartTask(scope.row)"
          >
            开始考试
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router'
import { ref, onMounted } from 'vue';

const route = useRoute()
const router = useRouter()
const schoolId = route.params.schoolId
const examsList = ref([])

const fetchExamList = async () => {
  try {
    console.log('当前学校ID:', schoolId)
    // 调用后端查询接口
    const response = await axios.post('http://localhost:8088/api/list',{
      schoolId: schoolId
    });
    examsList.value = response.data.examsList;
  } catch (error) {
    console.error('获取考试列表失败:', error);
  }
}

const handleStartTask = (row) => {
  window.location.href = "myapp://test";
  router.push('/page')
}

onMounted(() => {
  fetchExamList();
})
</script>

<style scoped>
.exam-list-container {
  padding: 20px;
}
</style>